package ipl.projet.domaine;

import ipl.projet.exceptions.CoordonneException;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Embeddable;

@Embeddable
public class Coordonnee implements Serializable {

	private static final long serialVersionUID = 1879729466319672050L;

	private static final int MIN_X = 0;
	private static final int MAX_X = 9;
	private static final int MIN_Y = 0;
	private static final int MAX_Y = 9;

	@Column(nullable = false)
	private int x;

	@Column(nullable = false)
	private int y;

	/* Constructeurs */
	public Coordonnee() {
	}

	public Coordonnee(int x, int y) throws CoordonneException {
		// Mis des constantes comme ca si on veut changer la taille, plus facile
		if (x < MIN_X || y < MIN_Y || x > MAX_X || y > MAX_Y)
			throw new CoordonneException();

		this.x = x;
		this.y = y;
	}

	/* Getters */
	public int getX() {
		return this.x;
	}

	public int getY() {
		return this.y;
	}

	@Override
	public boolean equals(Object obj) {
		if (this.x == ((Coordonnee) obj).x && this.y == ((Coordonnee) obj).y)
			return true;
		else
			return false;
	}

}
